<template>
    <Form
            :form-items="formItems"
            :format-form="formatForm"
    ></Form>
</template>

<script>
    import Form from '../../../../common-util/src/components/page/Form.vue'
    export default {
        components:{
            Form
        },
        data(){
            return {
                formItems:[
                    {
                        field: {
                            name: 'name'
                        },
                        element:{
                            label: '名称',
                            required: true
                        }
                    },
                    {
                        field: {
                            name: 'typeDictId'
                        },
                        element:{
                            type: 'selectDict',
                            selectDict:{
                                groupCode: 'clock_type'
                            },
                            label: '类型',
                            required: true
                        }
                    },
                    {
                        field: {
                            name: 'lateArriveMax'
                        },
                        element:{
                            type: 'inputNumber',
                            label: '最多可晚到(分)',
                            required: (form)=>{
                                return ['allow_earl_early_late_late','allow_earl_late'].some(item => {return item == form.typeDictId__code})
                            },
                            show: (form)=>{
                                return ['allow_earl_early_late_late','allow_earl_late'].some(item => {return item == form.typeDictId__code})
                            }
                        }
                    },
                    {
                        field: {
                            name: 'earlyLeaveMax'
                        },
                        element:{
                            type: 'inputNumber',
                            label: '最多早走(分)',
                            required: (form)=>{
                                return ['allow_earl_early_late_late','allow_earl_late'].some(item => {return item == form.typeDictId__code})
                            },
                            show: (form)=>{
                                return ['allow_earl_early_late_late','allow_earl_late'].some(item => {return item == form.typeDictId__code})
                            }
                        }
                    },
                    {
                        field: {
                            name: 'isNextDayLate'
                        },
                        element:{
                            type: 'switch',
                            label: '是否下班晚走，第二天可晚到',
                            required: true
                        }
                    },
                    {
                        field: {
                            name: 'lateLeave'
                        },
                        element:{
                            type: 'inputNumber',
                            label: '晚走(分)',
                            required: (form)=>{
                                return form.isNextDayLate
                            },
                            show: (form)=>{
                                return form.isNextDayLate
                            },
                        }
                    },
                    {
                        field: {
                            name: 'lateArrive'
                        },
                        element:{
                            type: 'inputNumber',
                            label: '可以晚到(分)',
                            required: (form)=>{
                                return form.isNextDayLate
                            },
                            show: (form)=>{
                                return form.isNextDayLate
                            },
                        }
                    },
                    {
                        field: {
                            name: 'remark'
                        },
                        element:{
                            label: '备注'
                        }
                    },
                    {
                        element:{
                            type: 'button',
                            button:[
                                {
                                    action: 'submit',
                                    requestMethod:'post',
                                    url: this.$baseURL.attend +  '/attend/clock',
                                    label: '保存'
                                },
                                {
                                    action: 'reset',
                                    label: '重置',
                                    type: 'default'
                                }
                            ]
                        }
                    }
                ]
            }
        },
        methods:{
            formatForm(form){
                if(!['allow_earl_early_late_late','allow_earl_late'].some(item => {return item == form.typeDictId__code})){
                    form.lateArriveMax = null
                    form.earlyLeaveMax = null
                }
                if(!form.isNextDayLate){
                    form.lateLeave = null
                    form.lateArrive = null
                }
                return form
            }
        }
    }
</script>

<style scoped>

</style>